package com.sgb.kjwl.view.ui.adapter.lease;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.CarBrandEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter2;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.ArrayList;
import java.util.List;

public class LeaseSearchTipAdapter extends BaseAdapter implements Filterable {

    private List<String> mList;
    private Context context;

    public LeaseSearchTipAdapter(Context context, List<String> acList) {
        this.mList = acList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.item_lease_search_tip, null);
            holder = new ViewHolder();
            holder.tvName = (TextView) convertView.findViewById(R.id.name);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.tvName.setText(mList.get(position));
        return convertView;
    }

    class ViewHolder {
        public TextView tvName;
    }

    @Override
    public Filter getFilter() {
        return new Filter() {
            @Override
            protected FilterResults performFiltering(CharSequence constraint) {
                FilterResults results = new FilterResults();
//                List queryUsers = userDb.query(prefix.toString());
                results.values = mList;
                results.count = mList.size();
                return results;
            }

            @Override
            protected void publishResults(CharSequence constraint, FilterResults results) {
//                List queryUsers = (List) results.values;
                //把结果读取出复制到users里
//                if (mList == null) {
//                    mList = new ArrayList();
//                }
//                if (mList.size() > 0) {
//                    mList.clear();
//                }
                notifyDataSetChanged();
            }
        };
    }

}